<?php

namespace Drupal\s_commerce_service\ViewsController;

use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceAmountRefundTypeViewsField;
use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceAmountViewsField;
use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceEditLinkViewsField;
use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceReceiptViewsField;
use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceStatusViewsField;
use Drupal\s_commerce_service\ViewsController\handler\field\SCommerceServiceTypeViewsField;
use Drupal\s_commerce_service\ViewsController\handler\filter\SCommerceServiceAmountRefundTypeViewsFilter;
use Drupal\s_commerce_service\ViewsController\handler\filter\SCommerceServiceReceiptViewsFilter;
use Drupal\s_commerce_service\ViewsController\handler\filter\SCommerceServiceStatusViewsFilter;
use Drupal\s_commerce_service\ViewsController\handler\filter\SCommerceServiceTypeViewsFilter;
use EntityDefaultViewsController;


class SCommerceServiceViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => SCommerceServiceEditLinkViewsField::class,
        ],
      ];
      $info[$table]['amount_refund_type'] = [
        'title' => '退款方式',
        'help' => '退款方式',
        'real field' => 'amount_refund_type',
        'field' => [
          'handler' => SCommerceServiceAmountRefundTypeViewsField::class,
        ],
        'filter' => [
          'handler' => SCommerceServiceAmountRefundTypeViewsFilter::class,
        ],
      ];
      $info[$table]['type'] = [
        'title' => '申请类型 0 仅退款 1 退货退款',
        'help' => '申请类型 0 仅退款 1 退货退款',
        'real field' => 'type',
        'field' => [
          'handler' => SCommerceServiceTypeViewsField::class,
        ],
        'filter' => [
          'handler' => SCommerceServiceTypeViewsFilter::class,
        ],
      ];
      $info[$table]['receipt'] = [
        'title' => '货物状态 0 未收到货 1 已收到货  退货退款时必为1',
        'help' => '货物状态 0 未收到货 1 已收到货  退货退款时必为1',
        'real field' => 'receipt',
        'field' => [
          'handler' => SCommerceServiceReceiptViewsField::class,
        ],
        'filter' => [
          'handler' => SCommerceServiceReceiptViewsFilter::class,
        ],
      ];
      $info[$table]['amount'] = [
        'title' => '退款金额 已收到货时 可以编辑',
        'help' => '退款金额 已收到货时 可以编辑',
        'real field' => 'amount',
        'field' => [
          'handler' => SCommerceServiceAmountViewsField::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 待审核 1 待退款 2 已完成 3 拒绝 4 待退货',
        'help' => '状态 0 待审核 1 待退款 2 已完成 3 拒绝 4 待退货',
        'real field' => 'status',
        'field' => [
          'handler' => SCommerceServiceStatusViewsField::class,
        ],
        'filter' => [
          'handler' => SCommerceServiceStatusViewsFilter::class,
        ],
      ];

      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
